import CONSTANT from '../constant';
import SphereSphereDetector from "./sphere-sphere-detector";
import GjkEpaDetector from "./gjk-epa-detector/gjk-epa-detector";
import BoxBoxDetector from "./box-box-detector/box-box-detector";
import SphereBoxDetector from "./sphere-box-detector";
import CapsuleCapsuleDetector from "./capsule-capsule-detector";
import SphereCapsuleDetector from "./sphere-capsule-detector";

export default class CollisionMatrix {
    constructor() {
        this.init();
    }

    //.........................................public................................................

    getDetector(geomType1,geomType2) {
        let t1=geomType1-CONSTANT.GEOMETRY_TYPE_NULL-1;
        let t2=geomType2-CONSTANT.GEOMETRY_TYPE_NULL-1;
        return this.detectors[t1][t2];
    }

    //.........................................private................................................

    init(){
        this.detectors = new Array(8);
        this.detectors[0] = new Array(8);
        this.detectors[1] = new Array(8);
        this.detectors[2] = new Array(8);
        this.detectors[3] = new Array(8);
        this.detectors[4] = new Array(8);
        this.detectors[5] = new Array(8);
        let gjkEpaDetector = new GjkEpaDetector();
        this.detectors[0][0] = new SphereSphereDetector();
        this.detectors[0][1] = new SphereBoxDetector(false);
        this.detectors[0][2] = gjkEpaDetector;
        this.detectors[0][3] = gjkEpaDetector;
        this.detectors[0][4] = new SphereCapsuleDetector(false);
        this.detectors[0][5] = gjkEpaDetector;
        this.detectors[1][0] = new SphereBoxDetector(true);
        this.detectors[1][1] = new BoxBoxDetector();
        this.detectors[1][2] = gjkEpaDetector;
        this.detectors[1][3] = gjkEpaDetector;
        this.detectors[1][4] = gjkEpaDetector;
        this.detectors[1][5] = gjkEpaDetector;
        this.detectors[2][0] = gjkEpaDetector;
        this.detectors[2][1] = gjkEpaDetector;
        this.detectors[2][2] = gjkEpaDetector;
        this.detectors[2][3] = gjkEpaDetector;
        this.detectors[2][4] = gjkEpaDetector;
        this.detectors[2][5] = gjkEpaDetector;
        this.detectors[3][0] = gjkEpaDetector;
        this.detectors[3][1] = gjkEpaDetector;
        this.detectors[3][2] = gjkEpaDetector;
        this.detectors[3][3] = gjkEpaDetector;
        this.detectors[3][4] = gjkEpaDetector;
        this.detectors[3][5] = gjkEpaDetector;
        this.detectors[4][0] = new SphereCapsuleDetector(true);
        this.detectors[4][1] = gjkEpaDetector;
        this.detectors[4][2] = gjkEpaDetector;
        this.detectors[4][3] = gjkEpaDetector;
        this.detectors[4][4] = new CapsuleCapsuleDetector();
        this.detectors[4][5] = gjkEpaDetector;
        this.detectors[5][0] = gjkEpaDetector;
        this.detectors[5][1] = gjkEpaDetector;
        this.detectors[5][2] = gjkEpaDetector;
        this.detectors[5][3] = gjkEpaDetector;
        this.detectors[5][4] = gjkEpaDetector;
        this.detectors[5][5] = gjkEpaDetector;
    }
}